<?php
class ControllerReportAccounting extends Controller
{
	private $error = array();
	
	public function ledger()
	{
		$this->load->model("report/accounting");
		
		$this->data['accounttype'] = array();
		$vouchergroups_expense = array(
				0 => array("vouchergroupid" => "VEXSP", "vouchergroupname" => "Payments to suppliers for goods and services (Ex: Purchase Order)"),
				1 => array("vouchergroupid" => "VEXCR", "vouchergroupname" => "Payments to customers for goods and services (Ex: Return order)"),
				2 => array("vouchergroupid" => "VEXES", "vouchergroupname" => "Salary"),
				3 => array("vouchergroupid" => "VEXEA", "vouchergroupname" => "Amortization (loss of intangible asset value over time)"),
				4 => array("vouchergroupid" => "VEXEO", "vouchergroupname" => "Office Operating cost / Purchase Assets (Ex: Electronic, Water, Buy assets for company using)"),
				5 => array("vouchergroupid" => "VEXSL", "vouchergroupname" => "DEBT/LOANS of partners"),
				6 => array("vouchergroupid" => "VEXCL", "vouchergroupname" => "DEBT/LOANS of customers"),
				7 => array("vouchergroupid" => "VEXEL", "vouchergroupname" => "DEBT/LOANS of employee"),
				8 => array("vouchergroupid" => "VEXSR", "vouchergroupname" => "RENT ASSETS or others from partners"),
				9 => array("vouchergroupid" => "VEXEM", "vouchergroupname" => "Marketing cost, public relationship"),
				10 => array("vouchergroupid" => "VEXCT", "vouchergroupname" => "Return the deposit for customer when they receive products"),
				11 => array("vouchergroupid" => "VEXCC", "vouchergroupname" => "Change money to customer"),
				12 => array("vouchergroupid" => "VEXEA", "vouchergroupname" => "Capital")
			);
			
		$vouchergroups_income = array(
				0 => array("vouchergroupid" => "VINCS", "vouchergroupname" => "Receipts from the sale of goods or services (Ex: Sale Order, Sale services )"),
				1 => array("vouchergroupid" => "VINEI", "vouchergroupname" => "Receipts from internal company (employee)"),
				2 => array("vouchergroupid" => "VINSR", "vouchergroupname" => "Receipts from the returning products to supplier"),
				3 => array("vouchergroupid" => "VINSL", "vouchergroupname" => "DPBT/LOANS of Suppliers"),
				4 => array("vouchergroupid" => "VINCL", "vouchergroupname" => "DPBT/LOANS of Customer"),
				5 => array("vouchergroupid" => "VINEL", "vouchergroupname" => "DPBT/LOANS of Employee"),
				6 => array("vouchergroupid" => "VINCD", "vouchergroupname" => "Receipts from customer deposit order/products"),
				7 => array("vouchergroupid" => "VINCH", "vouchergroupname" => "Receipts from customer change products"),
				8 => array("vouchergroupid" => "VINCO", "vouchergroupname" => "Receipts from customer for other activities"),
				9 => array("vouchergroupid" => "VINSC", "vouchergroupname" => "Supplier change money"),
				10 => array("vouchergroupid" => "VINEA", "vouchergroupname" => "Capital")
			);
			
		foreach($vouchergroups_expense as $item)
		{
			$this->data['accounttype'][$item['vouchergroupid']] = $item['vouchergroupname']; 
		}
		
		foreach($vouchergroups_income as $item)
		{
			$this->data['accounttype'][$item['vouchergroupid']] = $item['vouchergroupname']; 
		}
		
		//Date
		$this->data['search_fromdate'] = $this->request->post['search_fromdate'];
		$this->data['search_todate'] = $this->request->post['search_todate']; 
		if($this->request->post['search_fromdate'] == "")
		{
			$this->data['search_fromdate'] = date("01/m/Y");
		}
		
		
		if($this->request->post['search_todate'] == "")
		{
			$this->data['search_todate'] = date("d/m/Y");
		}
		
		$search_fromdate = $this->date->formatMySQLDateQuery($this->data['search_fromdate'],"DMY","-");
		$search_todate = $this->date->formatMySQLDateQuery($this->data['search_todate'],"DMY","-");
		
		
		$this->data['reports'] = $this->model_report_accounting->ledger($search_fromdate, $search_todate);
		
		$this->data['startamount'] = (float)$this->model_report_accounting->getstartvoucher($search_fromdate);
		
		
		
		$this->id='content';
		
		if($this->request->post['display'] == "report")
		{
			$this->template="report/account_ledger_print.tpl";
		}
		else
		{
			$this->template="report/account_ledger.tpl";
		}
		
		$this->layout="layout/function";
		
		$this->render();
	}
	
	
	public function bussinessresult()
	{
		$this->load->model("report/accounting");
		
		$this->data['accounttype'] = array();
		$vouchergroups_expense = array(
				0 => array("vouchergroupid" => "VEXSP", "vouchergroupname" => "Payments to suppliers for goods and services (Ex: Purchase Order)"),
				1 => array("vouchergroupid" => "VEXCR", "vouchergroupname" => "Payments to customers for goods and services (Ex: Return order)"),
				2 => array("vouchergroupid" => "VEXES", "vouchergroupname" => "Salary"),
				3 => array("vouchergroupid" => "VEXEA", "vouchergroupname" => "Amortization (loss of intangible asset value over time)"),
				4 => array("vouchergroupid" => "VEXEO", "vouchergroupname" => "Office Operating cost / Purchase Assets (Ex: Electronic, Water, Buy assets for company using)"),
				5 => array("vouchergroupid" => "VEXSL", "vouchergroupname" => "DEBT/LOANS of partners"),
				6 => array("vouchergroupid" => "VEXCL", "vouchergroupname" => "DEBT/LOANS of customers"),
				7 => array("vouchergroupid" => "VEXEL", "vouchergroupname" => "DEBT/LOANS of employee"),
				8 => array("vouchergroupid" => "VEXSR", "vouchergroupname" => "RENT ASSETS or others from partners"),
				9 => array("vouchergroupid" => "VEXEM", "vouchergroupname" => "Marketing cost, public relationship"),
				10 => array("vouchergroupid" => "VEXCT", "vouchergroupname" => "Return the deposit for customer when they receive products"),
				11 => array("vouchergroupid" => "VEXCC", "vouchergroupname" => "Change money to customer"),
				12 => array("vouchergroupid" => "VEXEA", "vouchergroupname" => "Capital")
			);
			
		$vouchergroups_income = array(
				0 => array("vouchergroupid" => "VINCS", "vouchergroupname" => "Receipts from the sale of goods or services (Ex: Sale Order, Sale services )"),
				1 => array("vouchergroupid" => "VINEI", "vouchergroupname" => "Receipts from internal company (employee)"),
				2 => array("vouchergroupid" => "VINSR", "vouchergroupname" => "Receipts from the returning products to supplier"),
				3 => array("vouchergroupid" => "VINSL", "vouchergroupname" => "DPBT/LOANS of Suppliers"),
				4 => array("vouchergroupid" => "VINCL", "vouchergroupname" => "DPBT/LOANS of Customer"),
				5 => array("vouchergroupid" => "VINEL", "vouchergroupname" => "DPBT/LOANS of Employee"),
				6 => array("vouchergroupid" => "VINCD", "vouchergroupname" => "Receipts from customer deposit order/products"),
				7 => array("vouchergroupid" => "VINCH", "vouchergroupname" => "Receipts from customer change products"),
				8 => array("vouchergroupid" => "VINCO", "vouchergroupname" => "Receipts from customer for other activities"),
				9 => array("vouchergroupid" => "VINSC", "vouchergroupname" => "Supplier change money"),
				10 => array("vouchergroupid" => "VINEA", "vouchergroupname" => "Capital")
			);
			
		foreach($vouchergroups_expense as $item)
		{
			$this->data['accounttype'][$item['vouchergroupid']] = $item['vouchergroupname']; 
		}
		
		foreach($vouchergroups_income as $item)
		{
			$this->data['accounttype'][$item['vouchergroupid']] = $item['vouchergroupname']; 
		}
		
		//Date
		$this->data['search_fromdate'] = $this->request->post['search_fromdate'];
		$this->data['search_todate'] = $this->request->post['search_todate']; 
		if($this->request->post['search_fromdate'] == "")
		{
			$this->data['search_fromdate'] = date("01/m/Y");
		}
		
		
		if($this->request->post['search_todate'] == "")
		{
			$this->data['search_todate'] = date("d/m/Y");
		}
		
		$search_fromdate = $this->date->formatMySQLDateQuery($this->data['search_fromdate'],"DMY","-");
		$search_todate = $this->date->formatMySQLDateQuery($this->data['search_todate'],"DMY","-");
		
		
		$this->data['reports'] = array();
		$data = $this->model_report_accounting->businessresult($search_fromdate, $search_todate);
		
		for($i=0; $i<count($data); $i++)
		{
			$this->data['reports'][$data[$i]['vouchertype']]['vouchertype'] = $data[$i]['vouchertype'];
			$this->data['reports'][$data[$i]['vouchertype']]['items'][] = $data[$i]; 
		}
		
		$this->id='content';
		
		if($this->request->post['display'] == "report")
		{
			$this->template="report/account_bussinessresult_print.tpl";
		}
		else
		{
			$this->template="report/account_bussinessresult.tpl";
		}
		
		$this->layout="layout/function";
		
		$this->render();
	}
	
}
?>